home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
boe.pres.k12.wv.us
/
boe.pres.k12.wv.us.zip
/
boe.pres.k12.wv.us
/
Utilities
/
Xerox Workcentre 5335
/
Windows Scan
/
32-bit_x86
/
Francais
/
cpsimage.cab
/
data
/
cpsimaging.elf
next >
Wrap
Text File
|
2010-03-31
|
16KB
|
425 lines
/*
** $Id: cpsimaging.elf,v 1.48 2010/03/29 14:27:07 campanel Exp $
**
** Classes for CPSIMAGING "package"
** CPSIMAGING is an optimized interface for the CPS Scaning Drivers
**
*******************************************************************************/
#load "docio/doctransforms.elf";
#load "xipProcs/xipflatten.proc";
// #load "xipProcs/printImageLayers.proc";
/******************************************************************************/
/* @CPSCONTROLLER
// DESCRIPTION
This class is used to control thumbnail creation, Memory DIB access, and a
limited set of file conversions for the CPS Scan Drivers
*/
/* @initialize Causes the controller environment to be initialized. */
/******************************************************************************/
CLASS CPSCallback {
METHOD CPSDocumentInfoCB (
POINTER pInfo, INTEGER width, INTEGER height, INTEGER bpl, INTEGER seps,
STRING format, INTEGER pages, INTEGER bps, INTEGER compress,
INTEGER xres, INTEGER yres
) NATIVE "CPSInfoCallback@cpsimage2";
METHOD CPSGetImageData(XIPIMAGE img, POINTER dest) RETURNS (INTEGER count)
NATIVE "getXIPImageData@xiputil";
}
/******************************************************************************/
/* @CPSCONTROLLER
// DESCRIPTION
This class is used to control thumbnail creation, Memory DIB access, and a
limited set of file conversions for the CPS Scan Drivers
*/
/* @initialize Causes the controller environment to be initialized. */
/******************************************************************************/
CLASS CPSCONTROLLER
{
XIPIMAGE flatImg; // We want to keep conversions to a minimum
STRING docid; // document id for the current conversion
STRING fmt; // format of the current document
INTEGER pgnum; // page number for already flattened image
METHOD initialize ()
{
if (this.isInitialized == FALSE)
this.isInitialized = TRUE;
}
METHOD setImgCache (XIPIMAGE img, STRING id, DOCUMENTREADER dr, INTEGER page)
{
if ( !this.flatImg || this.docid != id || this.pgnum != page ) {
this.flatImg = Flatten ( imgIn: img.Copy() );
this.docid = id;
this.pgnum = page;
}
if ( ( !this.fmt && dr ) || ( id != this.docid ) ) {
STRING fmt;
dr.getFormat() Returns (format: fmt);
this.fmt = fmt;
}
}
METHOD initDocument(STRING filename, STRING docid)
{
DOCUMENTREADER dr = CreateDocumentReader (filename: filename);
if (dr)
this.docs.insert(name: docid, obj: dr);
else
SetStatus( op: "stop", msg:
"CPSCONTROLLER::initDocument unable to create DOCUMENTREADER\n");
}
METHOD getDocumentImage(STRING docid) RETURNS (CPSDocumentInfo dinfo)
{
dinfo.format = "PDF";
dinfo.pixels = 255;
dinfo.scanlines = 4095;
}
METHOD getRasterLayer (XIPIMAGE img) Returns (XIPIMAGE raster)
{
INTEGER ii, ltype;
raster = img;
if ( img.nlayers == 1 ) return;
for( ii=0; ii<img.nlayers; ii++ ) {
raster = img.getLayer ( num: ii );
ltype = raster.getMember (member: "layerType");
if ( ltype == XIP_Contone || ltype == XIP_Binary ||
ltype == XIP_ColorMask || ltype == XIP_ContoneMask ) {
// capture base settings
raster.resolution = (img.resolution[0], img.resolution[1]);
raster.imageHeight = img.imageHeight;
raster.imageWidth = img.imageWidth;
return;
}
}
print "No raster layer found!!!!";
}
METHOD getDocumentInfo( STRING docid, POINTER ep )
{
DOCUMENTREADER dr = this.docs.ref(name: docid);
if (!dr)
{
SetStatus( op: "stop", msg:
"CPSCONTROLLER::getDocumentInfo unable to get DOCUMENTREADER\n");
return;
}
XIPIMAGE xi = dr.getPage(pgnum: 1);
if (!xi)
{
SetStatus( op: "stop", msg:
"CPSCONTROLLER::getDocumentInfo unable to getPage\n");
return;
}
this.setImgCache (img:xi, id:docid, dr:dr, page:1);
xi = this.getRasterLayer ( img: this.flatImg );
CPSCallback cpscb;
cpscb.CPSDocumentInfoCB (
pInfo: ep,
width: xi.getMember(member: "pixels"),
height: xi.getMember(member: "scanlines"),
bpl: xi.getMember(member: "bytes"),
seps: xi.getMember(member: "seps"),
format: this.fmt,
pages: dr.getPageCount(),
bps: xi.getMember(member: "bits"),
compress: xi.getMember(member: "compression"),
xres: xi.resolution[0],
yres: xi.resolution[1]
);
}
METHOD makeThumbnail ( STRING docid, STRING outfile, INTEGER width, INTEGER height )
{
DOCUMENTREADER dr = this.docs.ref(name: docid);
if (!dr)
{
SetStatus( op: "stop", msg:
"CPSCONTROLLER:makeThumbnail unable to get DOCUMENTREADER");
return;
}
try {
DOCUMENTWRITER dw = CreateDocumentWriter( filename: outfile);
} catch {
try { print "Unable to make DOCUMENTWRITER object for filename " + outfile;
print "Fall back is \"bmp\" format";
DOCUMENTWRITER dw = CreateDocumentWriter( filename: outfile, format: "bmp" ); }
catch {
SetStatus( op: "stop",
msg: "CPSCONTROLLER:makeThumbnail unable to create DocumentWriter for \"" +
outfile + "\"");
return;
}
}
// Turn off page numbering for single page file formats
dw.setAttr(name:"_DIOnoPageNumFilename", obj:1);
// make a new image by transforming the input page
XIPIMAGE xim = dr.getPage(pgnum: 1);
if (!xim)
{
SetStatus( op: "stop", msg: "CPSCONTROLLER:makeThumbnail Not able to get page");
return;
}
this.setImgCache (img:xim, id:docid, dr:dr, page:1);
xim = this.getRasterLayer ( img: this.flatImg );
INTEGER photo, v, w, h;
w = width; h = height;
// basic formatting
xim = xim.unCompress().unmap().thumbnail (size:(w, h));
// pad to keep aspect ratio of thumbnail
w = width - xim.getMember (member:"pixels");
h = height - xim.getMember (member:"scanlines");
photo = xim.getMember (member: "photometry");
if ( photo != XIP_K_COLOR ) v = 255;
xim = xim.frame (value: (v,v,v), outside:TRUE, thick:(w/2,w/2,h/2,h/2) );
if ( xim.getMember (member:"photometry") == XIP_DEVICERGB_COLOR )
xim = xim.modheader( modify: ("Photometry:name:srgb") ).exec();
// pretty much everything needs pixel interleaved data
if ( xim.getMember (member:"compression") == 0 )
xim = xim.interleave (pixel: TRUE);
if ( xim.getMember (member:"photometry") == XIP_K_COLOR )
xim = xim.cspace(outspace:"gray");
if ( xim.getMember (member: "compression") == XIP_JPEG_COMP )
xim = xim.jprecomp (mbands: TRUE);
// Since the page is now fully rendered adjust dimensions
xim.imageWidth = xim.getMember(member: "pixels");
xim.imageHeight = xim.getMember(member: "scanlines");
xim.setMember (member: "width", value: xim.imageWidth);
xim.setMember (member: "height", value: xim.imageHeight);
dw.appendPage (pgImg:xim);
// force the file to be written and release page resources
dw.release();
}
METHOD getSizeForDIB ( STRING docid, INTEGER pageNum, POINTER info )
RETURNS ( INTEGER memsize )
{
STRING me = "CPSCONTROLLER::getSizeForDIB";
DOCUMENTREADER dr = this.docs.ref(name: docid);
if (!dr)
{
SetStatus( op: "stop", msg: me + " Could not find document reference\n");
return;
}
if ( pageNum <= 0 ) pageNum = 1;
XIPIMAGE xim = dr.getPage(pgnum: pageNum);
if (!xim)
{
SetStatus( op: "stop", msg: me + " Unable to getPage\n");
return;
}
this.setImgCache (img:xim, id:docid, dr:dr, page:pageNum);
xim = this.getRasterLayer ( img: this.flatImg );
if ( xim.getMember (member: "photometry") == XIP_BUILDMAP_COLOR)
xim = xim.unmap();
xim = xim.interleave(pixel: TRUE);
INTEGER bitsPerSpot = xim.getMember(member: "bits") * xim.getMember(member: "seps");
INTEGER bitsPerLine = xim.getMember(member: "pixels") * bitsPerSpot;
INTEGER padWordsPerLine = (bitsPerLine + 31) / 32;
INTEGER padBytesPerLine = padWordsPerLine * 4;
memsize = xim.getMember(member: "scanlines") * padBytesPerLine;
CPSCallback cpscb;
cpscb.CPSDocumentInfoCB (
pInfo: info,
width: xim.getMember(member: "pixels"),
height: xim.getMember(member: "scanlines"),
bpl: xim.getMember(member: "bytes"),
seps: xim.getMember(member: "seps"),
format: this.fmt,
pages: 1,
bps: xim.getMember(member: "bits"),
compress: xim.getMember(member: "compression"),
xres: xim.resolution[0],
yres: xim.resolution[1]
);
}
METHOD getDocumentData ( STRING docid, INTEGER pageNum, POINTER data, POINTER info )
RETURNS ( INTEGER count )
{
STRING me = "CPSCONTROLLER::getDocumentData";
DOCUMENTREADER dr = this.docs.ref(name: docid);
if (!dr)
{
SetStatus( op: "stop", msg: me + " Could not find document reference");
return;
}
if ( pageNum <= 0 ) pageNum = 1;
XIPIMAGE xim = dr.getPage(pgnum: pageNum);
if (!xim)
{
SetStatus( op: "stop", msg: me + " Unable to getPage");
return;
}
/* Requires non-MRC, uncompressed data */
XIPIMAGE outpage;
this.setImgCache (img: xim, id: docid, dr: dr, page: pageNum);
outpage = this.flatImg;
outpage = this.getRasterLayer ( img: outpage);
if ( outpage.getMember (member: "photometry") == XIP_BUILDMAP_COLOR)
outpage = outpage.unmap();
outpage = outpage.interleave(pixel: TRUE
).pad(align: 4
).exec();
// Correction for PDF inputs that default sRGB to DEVICERGB
if ( outpage.getMember (member:"photometry") == XIP_DEVICERGB_COLOR )
outpage = outpage.modheader( modify: ("Photometry:name:srgb") );
// Want data in DIB format
if ( outpage.getMember(member: "seps") == 3 ) {
outpage = outpage.rotate(angle:"miry"
).cspace(outspace:"sbgr"
).interleave(pixel:TRUE
).pad(align:4
).exec();
} else { // the cspace is here to avoid writing out XIP_K_COLOR
outpage = outpage.rotate(angle:"miry"
).cspace(outspace:"gray"
).pad(align:4
).exec();
}
CPSCallback cpscb;
cpscb.CPSDocumentInfoCB (
pInfo: info,
width: outpage.getMember(member: "pixels"),
height: outpage.getMember(member: "scanlines"),
bpl: outpage.getMember(member: "bytes"),
seps: outpage.getMember(member: "seps"),
format: this.fmt,
pages: 1,
bps: outpage.getMember(member: "bits"),
compress: outpage.getMember(member: "compression"),
xres: outpage.resolution[0],
yres: outpage.resolution[1]);
count = cpscb.CPSGetImageData( img: outpage, dest: data);
}
// This really converts the whole document, not just a page
METHOD convertPage ( STRING docid, STRING outfile, STRING format, BOOLEAN test )
{
DOCUMENTREADER dr = this.docs.ref(name: docid);
if (!dr)
{
SetStatus( op: "stop",
msg: "CPSCONTROLLER::convertPage unable to get document reference\n");
return;
}
DOCUMENTWRITER dw = CreateDocumentWriter( filename: outfile, testfile: test, format: format);
INTEGER ii, photo;
INTEGER pgcnt = dr.getPageCount();
XIPIMAGE xim, ximt;
for (ii=1; ii<=pgcnt; ii++)
{
xim = dr.getPage(pgnum: ii);
if (!xim)
{
SetStatus( op: "stop", msg: "CPSCONTROLLER::convertPage unable to getPage\n");
return;
}
// xim.Write(filename: "foo.obj");
photo = this.getRasterLayer ( img: xim ).getMember (member:"photometry");
// print photo;
if ( format == "PDF" && photo != XIP_BUILDMAP_COLOR) {
ximt = xim;
} else if ( format == "XPS" ) { // should just work no matter what type of image
ximt = xim;
} else { // most likely going to some raster format at this point
this.setImgCache (img:xim, id:docid, dr:dr, page:ii);
xim = this.getRasterLayer ( img: this.flatImg );
// Nothing should come in as device except from PDF which calls sRGB DEVICERGB
if ( photo == XIP_DEVICERGB_COLOR ) {
if ( xim.getMember (member:"compression") == XIP_JPEG_COMP )
xim = xim.modheader( modify: ("Photometry:name:ycbcr") );
else
xim = xim.modheader( modify: ("Photometry:name:sRGB") );
}
// Currently don't handle mapped images very well
else if ( photo == XIP_BUILDMAP_COLOR ) {
xim = xim.unmap(pixel: TRUE);
}
ximt = TransformPage(inpage:xim.exec(), todoc:dw);
if ( ximt.getMember (member: "compression") == XIP_JPEG_COMP )
ximt = ximt.jprecomp (mbands: TRUE);
/* clean any remaining transforms */
ximt = ximt.exec();
ximt.clearAttr (name: "_PDFTransform", num: 0);
ximt.clearAttr (name: "_XPSTransform", num: 0);
}
dw.appendPage( pgImg: ximt );
}
// force the file to be written and release page resources
dw.release();
}
METHOD closeDocument ( STRING docid )
{
DOCUMENTREADER dr = this.docs.extract(name: docid);
if (!dr)
{
SetStatus( op: "continue",
msg: "CPSCONTROLLER::closeDocument unable to closeDocument\n");
return;
}
dr.release();
}
/************ Internal Data Members **************/
BOOLEAN isInitialized = FALSE;
LIST docs;
}